jsx3.lang.Package.definePackage("tibco.admin.enterpriseAssets.envDef.envDtls", function (envDtls) {
});

/**
 * Env Details: Obeserver it extended from LayoutGrid because this Plug-in container root object
 * is LayoutGrid.
 */
jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.envDef.envDtls.EnvDtls",
        com.gix.gui.LeftSelectPane,
        [tibco.admin.plugin.PluginContainerInterface],
        function (plugin) {
            plugin.prototype.tabsToLoad = new Object();
            plugin.prototype.allTabs = new Object();
            plugin.prototype.currentButton = null;

            //load all resources
            plugin.prototype.loadResources = function() {
              if (this.getPluginList().size() == 0) {
                var preLoad = new jsx3.util.List(0);

                // load Gen Info
                if (!tibco.admin.enterpriseAssets.envDef.envDtls.genInfo || !tibco.admin.enterpriseAssets.envDef.envDtls.genInfo.GenInfoPlugin) {
                    try {
                        tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/envDef/envDtls/genInfo/GenInfoPlugin.js", "tibco.admin");
                        preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.genInfo.GenInfoPlugin, preLoad.size());

                    }
                    catch(ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                else {
                    preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.genInfo.GenInfoPlugin, preLoad.size());
                }


                // load Mediation Bus
                if (!tibco.admin.enterpriseAssets.envDef.envDtls.medBus || !tibco.admin.enterpriseAssets.envDef.envDtls.medBus.MedBus) {
                    try {
                        tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/envDef/envDtls/medBus/MedBus.js", "tibco.admin");
                        preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.medBus.MedBus, preLoad.size());

                    }
                    catch(ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                else {
                    preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.medBus.MedBus, preLoad.size());
                }


                // load Machines
                if (!tibco.admin.enterpriseAssets.envDef.envDtls.eMachines || !tibco.admin.enterpriseAssets.envDef.envDtls.eMachines.EnvMachinesPlugin) {
                    try {
                        tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/envDef/envDtls/eMachines/EnvMachinesPlugin.js", "tibco.admin");
                        preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.eMachines.EnvMachinesPlugin, preLoad.size());
                    }
                    catch(ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                else {
                    preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.eMachines.EnvMachinesPlugin, preLoad.size());
                }


                // load UDDI
                if (!tibco.admin.enterpriseAssets.envDef.envDtls.uddi || !tibco.admin.enterpriseAssets.envDef.envDtls.uddi.UddiPlugin) {
                    try {
                        tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/envDef/envDtls/uddi/UddiPlugin.js", "tibco.admin");
                        preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.uddi.UddiPlugin, preLoad.size());
                    }
                    catch(ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                else {
                    preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.uddi.UddiPlugin, preLoad.size());
                }


                //load Shared Resources
                if (!tibco.admin.enterpriseAssets.envDef.envDtls.shdResDefs || !tibco.admin.enterpriseAssets.envDef.envDtls.shdResDefs.ShdResDefs) {
                    try {
                        tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/envDef/envDtls/shdResDefs/ShdResDefs.js", "tibco.admin");
                        preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.shdResDefs.ShdResDefs, preLoad.size());

                    }
                    catch(ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                else {
                    preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.shdResDefs.ShdResDefs, preLoad.size());
                }

/*
                if (!tibco.admin.enterpriseAssets.envDef.envDtls.keystore || !tibco.admin.enterpriseAssets.envDef.envDtls.keystore.KeystorePlugin) {
                    try {
                        tibco.admin.Main.loadClass("tibco/admin/enterpriseAssets/envDef/envDtls/keystore/KeystorePlugin.js", "tibco.admin");
                        preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.keystore.KeystorePlugin, preLoad.size());

                    }
                    catch(ex) {
                        tibco.admin.Main.logException(ex);
                    }
                }
                else {
                    preLoad.add(tibco.admin.enterpriseAssets.envDef.envDtls.keystore.KeystorePlugin, preLoad.size());
                }
				*/

                this.loadPlugins("tibco.admin.enterpriseAssets.envDef.envDtls.EnvDtlsNavInterface", preLoad);
               }
               else {
                    this.onAfterGetPlugins();
               }
            }

            plugin.prototype.loadButton = function(objEvent) {

                var parentPane = objEvent.target.getContentPane();
                var label = objEvent.target.getText();
                var plugInComponent = this.tabsToLoad[label];
                if (plugInComponent) {
                    plugInComponent.loadComponent(parentPane);
                    this.currentButton = plugInComponent;
                    delete this.tabsToLoad[label];
                }
                else {
                    plugInComponent = this.allTabs[label];
                    if(plugInComponent) {
                        this.currentButton = plugInComponent;
                        setTimeout(function() {
                            plugInComponent.buttonSelected();
                        }, 0);
                    }
                }
            }

            // This is the hook provided by Plug-in API, which will be called after the load Plugins call.
            plugin.prototype.onAfterGetPlugins = function() {
                var me = this;
                this.subscribe(com.gix.gui.LeftSelectPane.BUTTON_SELECTED, me, me.loadButton);
                var first = true;
                var iter = this.getPluginList("tibco.admin.enterpriseAssets.envDef.envDtls.Details").iterator();
                while (iter.hasNext()) {
                    var pluginComponent = iter.next();
                    var labelText = pluginComponent.getNavLinkText();
                    var button = this.addButton(labelText);
                    if (first) {
                        pluginComponent.loadComponent(button.getContentPane());
                        this.allTabs[labelText] = pluginComponent;
                        this.currentButton = pluginComponent;
                        first = false;
                    } else {
                        this.tabsToLoad[labelText] = pluginComponent;
                        this.allTabs[labelText] = pluginComponent;
                    }
                }

            }

            plugin.prototype.setupPlugin = function(pluginInstance) {
            }

            plugin.prototype.subscribeAll = function() {
                tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.envDef.EventID.ENVIRONMENT_ROW_SELECTED, this, this.loadName);
            }

            plugin.prototype.unsubscribeAll = function() {
                tibco.admin.PubSub.unsubscribe(tibco.admin.enterpriseAssets.envDef.EventID.ENVIRONMENT_ROW_SELECTED, this);
            }

            plugin.prototype.loadName = function(objEvent) {
                this.getDescendantOfName("lblSectionTitle27A1").setText(objEvent.environmentName?objEvent.environmentName:"", true);
            }

            plugin.prototype.containerBeginEdit = function(objPlugin) {
                //                if(this.beginEditMode) {
                this.handler.beginEditMode();
                //                }
                this.beginEdit(objPlugin);
            }

            plugin.prototype.containerEndEdit = function(objPlugin) {
                //                if(this.endEditMode && !this.childIsInEditMode()) {
                this.handler.endEditMode();
                //                }
                this.endEdit(objPlugin);
            }

            plugin.prototype.beginEdit = function(objPlugin) {
                //find proper button for plugin first!!!! then setEditMode(button, val)
                this.setSelectedEditMode(true);
            }

            plugin.prototype.endEdit = function(objPlugin) {
                this.setSelectedEditMode(false);
            }

            plugin.prototype.getComponentPath = function() {
                return  "tibco/admin/enterpriseAssets/envDef/envDtls/component.xml"
            }

            plugin.prototype.refresh = function() {
                if(this.currentButton) {
                    var me = this;
                    setTimeout(function() {
                        me.currentButton.buttonSelected();
                    }, 0);
                }
            }
        });
